#include "altlauncher.h"

#include "altmaterialwidget.h"
#include "altpluginviewer.h"

#include <QAction>
#include <QCoreApplication>
#include <QMdiArea>
#include <QMdiSubWindow>
#include <QMenu>
#include <QMenuBar>

namespace Alt {
     Launcher::Launcher(QWidget* widget) : QMainWindow(widget) {
          init();
     }

     void Launcher::showPluginViewer() {
          PluginViewer dlg(this);
          dlg.exec();
          return;
     }

     //private
     void Launcher::init(){
          m_mdiArea = new QMdiArea(this);
          setCentralWidget(m_mdiArea);

          m_materialEditor = new MaterialWidget(false, this);
          QMdiSubWindow* materialsSubWindow = m_mdiArea->addSubWindow(m_materialEditor);
          materialsSubWindow->setAttribute(Qt::WA_DeleteOnClose, false);
          materialsSubWindow->hide();

          initMenus();
          return;
     }

     void Launcher::initMenus(){
          //Edit
          QMenu* editMenu = menuBar()->addMenu(tr("&Edit"));

          QAction* editMaterialsAction = editMenu->addAction(tr("&Materials"));
          editMaterialsAction->setShortcut(tr("ctrl+m"));
          editMaterialsAction->setStatusTip(tr("Edit material names."));
          connect(editMaterialsAction, SIGNAL(triggered()), m_materialEditor, SLOT(show()));

          //About
          QMenu* aboutMenu = menuBar()->addMenu(tr("&About"));

          QAction* aboutPluginsAction = aboutMenu->addAction(tr("&Plugins"));
          aboutPluginsAction->setShortcut(tr("ctrl+p"));
          aboutPluginsAction->setStatusTip(tr("View all availible Alt plugins."));
          connect(aboutPluginsAction, SIGNAL(triggered()), this, SLOT(showPluginViewer()));

          QAction* aboutQtAction = aboutMenu->addAction(tr("&Qt"));
          aboutQtAction->setStatusTip(tr("View information on Qt."));
          connect(aboutQtAction, SIGNAL(triggered()), qApp, SLOT(aboutQt()));
     }
}
